package mwt.xml.xdbforms.schemalayer.types;

import java.math.BigInteger;
import javax.xml.XMLConstants;
import mwt.xml.xdbforms.dblayer.metadata.impl.ColumnMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;

/**
 * 
 * @author Gianfranco Murador, Matteo Ferri, Cristian Castiglia
 */
public class XmlBigInt extends XmlInteger {

    public XmlBigInt(Document doc) {
        super(doc);
    }

    XmlBigInt() {
        
    }

    private void buildFragment(ColumnMetaData cmd) {

        Element xtype;
        Element restriction, maxInclusive, minInclusive;
        fragment = doc.createDocumentFragment();
        typeName = cmd.getTypeName();
        xtype = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:simpleType");
        xtype.setAttribute("name", typeName);
        cmd.setXschemaTypeName(typeName);

        restriction = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:restriction");
        restriction.setAttribute("base", "xs:integer");

        maxInclusive = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:maxInclusive");
        maxInclusive.setAttribute("value", Long.toString(Long.MAX_VALUE));
        minInclusive = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:minInclusive");
        minInclusive.setAttribute("value", Long.toString(Long.MIN_VALUE));

        // Costruisci il sottoalbero

        xtype.appendChild(restriction);
        restriction.appendChild(maxInclusive);
        restriction.appendChild(minInclusive);
        fragment.appendChild(xtype);





    }

    @Override
    public Object getXSchemaToJavaType(String baseType, String value) {

        BigInteger integer = new BigInteger(value);
        return integer;
    }

    @Override
    public DocumentFragment getSchemaType(ColumnMetaData cmd) {

        buildFragment(cmd);
        return fragment;

    }
}

